package com.penghaisoft.microwms.product.web.controller.insidewarehouse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.penghaisoft.microwms.common.controller.BaseController;
import com.penghaisoft.microwms.common.dto.Resp;
import com.penghaisoft.microwms.common.dto.TransResult;
import com.penghaisoft.microwms.common.page.Pager;
import com.penghaisoft.microwms.common.wms.model.ProContractChangePlanSn;
import com.penghaisoft.microwms.product.service.IProContractChangePlanSnService;

import lombok.extern.slf4j.Slf4j;

/**
 * @Package com.penghaisoft.microwms.product.web.controller.insidewarehouse
 * @ClassName: ProContractChangePlanSnController
 * @Description: 成品合同变更明细
 * @author luoteng
 * @date 2019年3月7日 下午1:02:23
 */
@RestController
@RequestMapping(value = "/proContractChangeSn")
@Slf4j
public class ProContractChangePlanSnController extends BaseController {

	@Autowired
	private IProContractChangePlanSnService proContractChangePlanSnService;

	/**
	 * 新增记录
	 * 
	 * @param proContractChangePlanSn
	 * @return
	 */
	@PostMapping("c")
	public TransResult create(ProContractChangePlanSn proContractChangePlanSn) {
		proContractChangePlanSn.preInsert();
		Resp resp = proContractChangePlanSnService.create(proContractChangePlanSn);
		return fromResp(resp);
	}

	/**
	 * 删除记录（逻辑删除active_flag=0)
	 * 
	 * @param proContractChangePlanSn
	 * @return
	 */
	@PostMapping("d")
	public TransResult delete(ProContractChangePlanSn proContractChangePlanSn) {
		proContractChangePlanSn.preUpdate();
		Resp resp = proContractChangePlanSnService.delete(proContractChangePlanSn);
		return fromResp(resp);
	}

	/**
	 * 查询列表
	 * 
	 * @param pager
	 * @return
	 */
	@PostMapping("list")
	public TransResult list(@RequestParam(name = "page", defaultValue = "1") int page,
			@RequestParam(name = "rows", defaultValue = "10") int rows,
			ProContractChangePlanSn proContractChangePlanSn) {
		Pager<ProContractChangePlanSn> result = proContractChangePlanSnService.findListByCondition(page, rows,
				proContractChangePlanSn);
		return success(result);
	}

	/**
	 * 查询单条
	 * 
	 * @param id
	 * @return
	 */
	@GetMapping("r/{id}")
	public TransResult queryById(@PathVariable String id) {
		ProContractChangePlanSn proContractChangePlanSn = proContractChangePlanSnService.findById(id);
		return success(proContractChangePlanSn);
	}

	/**
	 * 修改记录
	 * 
	 * @param proContractChangePlanSn
	 * @return
	 */
	@PostMapping("u")
	public TransResult update(ProContractChangePlanSn proContractChangePlanSn) {
		proContractChangePlanSn.preUpdate();
		Resp resp = proContractChangePlanSnService.update(proContractChangePlanSn);
		return fromResp(resp);
	}

}
